//
//  UIViewController+RootVC.m
//  DigitalEconomy_iOS
//
//  Created by Ding on 2020/3/17.
//  Copyright © 2020 DingC. All rights reserved.
//

#import "UIViewController+RootVC.h"



@implementation UIViewController (RootVC)
+ (UIViewController *)sj_topViewController:(UIViewController *)vc {
    if ([vc isKindOfClass:[UINavigationController class]]) {
        return [self sj_topViewController:[(UINavigationController *)vc topViewController]];
    } else if ([vc isKindOfClass:[UITabBarController class]]) {
        return [self sj_topViewController:[(UITabBarController *)vc selectedViewController]];
    } else {
        return vc;
    }
    return nil;
}

+ (UIViewController *)currentViewController {
    
    UIViewController *resultVC;
    resultVC = [self sj_topViewController:[[UIApplication sharedApplication].keyWindow rootViewController]];
    while (resultVC.presentedViewController) {
        resultVC = [self sj_topViewController:resultVC.presentedViewController];
    }
    return resultVC;
}
@end
